package com.vinci.task.controller;

import com.vinci.task.entity.TbTaskInfo;
import com.vinci.task.entity.TbTaskSelfRecommendationRegistration;
import com.vinci.task.service.TbTaskSelfRecommendationRegistrationService;
import com.vinci.util.JsonObject;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 自荐报名表 前端控制器
 * </p>
 *
 * @author 张先生
 * @since 2021-12-11
 */
@RestController
@RequestMapping("/task/Registration")
@Slf4j
public class TbTaskSelfRecommendationRegistrationController {

    @Autowired
    private TbTaskSelfRecommendationRegistrationService tbRegistrationService;

    /**
     * 查询自荐人员
     * @return
     */
    @PostMapping("/selectRegistration")
    public String selectRegistration(TbTaskSelfRecommendationRegistration tbRegistration,String taskId){

            if(tbRegistration!= null && taskId !=null){
                TbTaskInfo tbTaskInfo = tbRegistrationService.selectTaskInfo(taskId);
                List<TbTaskSelfRecommendationRegistration> tbTaskSelfRecommendationRegistrations = tbRegistrationService.selectRegistration(tbRegistration);
                tbTaskInfo.setTbTaskSelfRecommendationRegistration(tbTaskSelfRecommendationRegistrations);
                JSONObject jsonObject = JSONObject.fromObject(tbTaskInfo);
                String str = jsonObject.toString();
                return str;
            }else {
               String zzk ="A0400";
               JSONObject jsonObject = JSONObject.fromObject(zzk);
               String str = jsonObject.toString();
               return str;
            }

    }

    /**
     * 添加自荐人员
     * @return
     */
    @PostMapping("/insertRegistration")
    public JsonObject insertRegistration(TbTaskSelfRecommendationRegistration tbRegistration){
        JsonObject jsonObject = new JsonObject();
        if(tbRegistration!=null){
            tbRegistrationService.insertRegistration(tbRegistration);
            jsonObject.setCode("1");
            jsonObject.setMsg("添加成功");

        }else {
            jsonObject.setCode("A0400");
            jsonObject.setMsg("用户请求参数错误");
        }


        return jsonObject;
    }


}

